package com.kly.cashmall.services;

import com.kly.cashmall.AppApplication;
import com.kly.cashmall.utils.data.TextUtil;

/**
 * @author
 * @version $Id$
 * @since 2018/9/19 15:44
 */
public class UserInfoHelper {

    private UserInfoHelper() {
    }

    private static UserInfoHelper userInfoHelper;

    public static UserInfoHelper getInstance() {
        if (userInfoHelper == null) {
            synchronized (AppGlobalConfig.class) {
                if (userInfoHelper == null) {
                    userInfoHelper = new UserInfoHelper();
                }
            }
        }
        return userInfoHelper;
    }

    private String token;
    private String phoneNo;
    private String userCode;
    private String nickName;
    private boolean drawSwitch;
    private String userId;
    private boolean privacyIsShow;
    private int balance;
    private boolean isShowDeleteAccount;
    private boolean isFirstStart;


    public String getPhoneNo() {
        if (phoneNo == null)
            phoneNo = AppApplication.getStringPreference("phone_no", "");
        return phoneNo;
    }

    public void setPhoneNo(String phone) {
        this.phoneNo = phone;
        AppApplication.putPreference("phone_no", phone);
    }

    public String getToken() {
        if (token == null)
            token = AppApplication.getStringPreference("access_token", "");
        return token;
    }

    public void setToken(String token) {
        this.token = token;
        AppApplication.putPreference("access_token", token);
    }

    public boolean isLogin(){
        return !TextUtil.isEmpty(getToken());
    }

    public String getUserCode() {
        if (userCode == null)
            userCode = AppApplication.getStringPreference("user_code", "0");
        return userCode;
    }

    public void setUserCode(String code) {
        this.userCode = code;
        AppApplication.putPreference("user_code", code);
    }

    public boolean getDrawSwitch() {//true 为隐藏
            drawSwitch = AppApplication.getBPreference("drawSwitch",true);
        return drawSwitch;
    }

    public void setDrawSwitch(boolean drawSwitch) {
        this.drawSwitch = drawSwitch;
        AppApplication.putPreference("drawSwitch", drawSwitch);
    }

    public String getNickName() {
        if (nickName == null)
            nickName = AppApplication.getStringPreference("nickName", "游客");
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
        AppApplication.putPreference("nickName", nickName);
    }

    public String getUserId() {
        if (userId == null)
            userId = AppApplication.getStringPreference("userId", "");
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
        AppApplication.putPreference("userId", userId);
    }

    public boolean isPrivacyIsShow() {
        if (!privacyIsShow)
            privacyIsShow = AppApplication.getBPreference("privacyIsShow");
        return privacyIsShow;
    }

    public void setPrivacyIsShow(boolean privacyIsShow) {
        this.privacyIsShow = privacyIsShow;
        AppApplication.putPreference("privacyIsShow", privacyIsShow);

    }

    public int getBalance() {
            balance = AppApplication.getIntPreference("balance", 0);
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
        AppApplication.putIntPreference("balance", balance);

    }

    public boolean isShowDeleteAccount() {
        isShowDeleteAccount = AppApplication.getBPreference("showDeleteAccount",true);
        return isShowDeleteAccount;
    }

    public void setShowDeleteAccount(boolean showDeleteAccount) {
        isShowDeleteAccount = showDeleteAccount;
        AppApplication.putPreference("showDeleteAccount", showDeleteAccount);
    }

    public boolean isFirstStart() {
        isFirstStart = AppApplication.getBPreference("isFirstStart",true);
        return isFirstStart;
    }

    public void setFirstStart(boolean firstStart) {
        isFirstStart = firstStart;
        AppApplication.putPreference("isFirstStart", isFirstStart);
    }
}
